package edu.hawaii.duedates.libraries;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
//import static org.junit.Assert.
import java.util.List;
//import org.junit.Ignore;
import org.junit.Test;
import edu.hawaii.duedates.datastore.BorrowedItem;

/**
 * Test the UhLibrary class to check that it functions properly.
 * 
 * @author Erin Kim and Arthur Shum
 */
public class TestUhLibrary {

  /** The patron's UH ID number. */
  private final String uhId1 = System.getenv("DUEDATES_TESTUSER1_ID");
  private final String uhId2 = System.getenv("DUEDATES_TESTUSER2_ID"); 

  /** The patron's last name. */
  private final String lastName1 = System.getenv("DUEDATES_TESTUSER1_LASTNAME");
  private final String lastName2 = System.getenv("DUEDATES_TESTUSER2_LASTNAME");

  /**
   * Tests that logging in as account1 (which has no items checked-out) returns an empty List.
   * 
   * @throws Exception If an error occurs during the test.
   */
  @Test
  public void testNoResults() throws Exception {
    ILibrary uhl = new UhLibrary(uhId1, lastName1);
    List<BorrowedItem> results1 = uhl.getInfo();
    assertTrue("results1 is empty", results1.isEmpty()); 
  }

  /**
   * Tests that logging in as account2 (which has items checked-out) returns a non-empty List, and
   * that the List contains a BorrowedItem that has "UhLibrary" as its libraryName field.
   * 
   * @throws Exception If an error occurs during the test.
   */
  @Test
  public void testResultsExist() throws Exception {
    ILibrary uhl = new UhLibrary(uhId2, lastName2);
    List<BorrowedItem> results2 = uhl.getInfo();
    assertFalse("results2 is not empty", results2.isEmpty());
    
    BorrowedItem item = results2.get(0);
    assertEquals("Library name is correct", "University of Hawaii", item.getLibraryName());   
  }
  
  /**
   * Test that logging in with invalid credentials throws an exception.
   * 
   * @throws Exception If an error occurs during the test.
   */
  @Test(expected = Exception.class)
  public void testInvalidLogin() throws Exception {
    ILibrary uhl = new UhLibrary("12345", "abcde");
    uhl.getInfo();
    fail("Should not get here");
  }
  
  /**
   * Testing for empty login values.
   * 
   * @throws Exception If there is a problem with the getInfo method.
   */
  @Test(expected = Exception.class)
  public void testNullLogin() throws Exception {
    ILibrary uhl = new UhLibrary("", "");
    uhl.getInfo();
    fail("Should not get here");
  }
  
  
  
}
